package com.poetize.plus.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.poetize.plus.entity.dto.RoleDTO;
import com.poetize.plus.entity.dto.page.RolePageDTO;
import com.poetize.plus.entity.vo.page.RolePageVO;
import com.poetize.plus.entity.vo.RoleVO;
import com.poetize.plus.service.RoleService;
import com.poetize.plus.utils.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author zuosy
 * @created 2024/3/29 9:18
 */
@Tag(name = "角色信息--暂未启用")
@RestController
@RequestMapping("/admin/role")
@RequiredArgsConstructor
@Deprecated
public class RoleController {

    private final RoleService roleService;

    @GetMapping("/rolePage")
    @Operation(summary = "角色分页数据")
    @PreAuthorize(value = "hasRole('administrator')")
    public R<Page<RolePageVO>> rolePage(RolePageDTO rolePageDTO){
        return R.ok(roleService.rolePage(rolePageDTO));
    }

    @PostMapping("/addRole")
    @Operation(summary = "新增角色信息")
    @PreAuthorize(value = "hasRole('administrator')")
    public R<Boolean> addRole(@RequestBody @Validated(Insert.class) RoleDTO roleDTO){
        return R.ok(roleService.addRole(roleDTO));
    }

    @GetMapping("/{id}")
    @Operation(summary = "角色信息详情")
    @PreAuthorize(value = "hasRole('administrator')")
    public R<RoleVO> queryRole(@PathVariable("id") Long id){
        return R.ok(roleService.queryRole(id));
    }

    @PostMapping("/updateRole")
    @Operation(summary = "修改角色信息")
    @PreAuthorize(value = "hasRole('administrator')")
    public R<Boolean> updateRole(@RequestBody @Validated(Update.class) RoleDTO roleDTO){
        return R.ok(roleService.updateRole(roleDTO));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除角色信息")
    @PreAuthorize(value = "hasRole('administrator')")
    public R<Boolean> deleteRole(@PathVariable("id") Long id){
        return R.ok(roleService.deleteRole(id));
    }
}
